/*
 * CIIFView.java
 */

package ciif;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.io.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JFileChooser.*;
import java.beans.*;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import java.awt.*;
import java.util.prefs.*;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.event.ComponentEvent;
import javax.swing.BorderFactory;
import java.sql.ResultSet;
import java.sql.SQLException;


class CIIFImportLocalTaskListener implements PropertyChangeListener {
    javax.swing.JProgressBar pBar;
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if ("progress" == evt.getPropertyName()) {
            int progress = (Integer) evt.getNewValue();
            if (progress > 0) {
                pBar.setIndeterminate(false);
                pBar.setValue(progress);
                pBar.setString(progress + "%");
            }
        }
    }
    public void setPBar(javax.swing.JProgressBar bar) {
        pBar = bar;
    }
}

class CIIFImage {
    public String imageID;
    public String imagePath;
    public String thumbPath;
    public int imageViews;
    public String imageGroup;

    private CIIFDatabase db;

    public CIIFImage(String id, CIIFDatabase d) {
        imageID = id;
        db = d;
        loadImage();
    }

    private void loadImage() {
        ResultSet rs = db.loadRecord(imageID);
        try {
            if (rs.next()) {
                imagePath = rs.getString(2);
                thumbPath = rs.getString(3);
                imageViews = rs.getInt(4);
                imageGroup = rs.getString(5);
            } else {
                System.out.println("INVALID IMAGE: " + imageID);
            }
        } catch (SQLException sqle) {
            db.printSQLException(sqle);
        }

    }
}

class thumbPanel {
    public CIIFImage image;
    public JLabel label;
    public JPanel panel;

    public thumbPanel(CIIFImage i) {
        image = i;
        panel = new JPanel();
        label = new JLabel();
        panel.setBorder(BorderFactory.createEtchedBorder());
        label.setIcon(new ImageIcon(image.thumbPath));
        panel.add(label, BorderLayout.CENTER);
    }

    public void save() {
        System.out.println("Saved object.");
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("Object destroyed.");
    }

}

 
/**
 * The application's main frame.
 */
public class CIIFView extends FrameView {

    private Preferences prefs;
    private CIIFDatabase db;
    private CIIFConfigure configurePane;
    private CIIFImportLocalTask importTask;
    private java.util.List<thumbPanel> filterThumbPanelList = new java.util.ArrayList<thumbPanel>();
    private java.util.List<CIIFImage> CIIFImages = new java.util.ArrayList<CIIFImage>();
    private GridLayout filterThumbGridLayout = new GridLayout();
    private Boolean filterThumbLock = false;
    int filterThumbOldWidth;
    int filterThumbOldHeight;

    public CIIFView(SingleFrameApplication app) {
        super(app);
        
        //CIIFApp.getApplication().getMainFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //System.out.println(CIIFApp.getApplication().getMainFrame().getDefaultCloseOperation());

        initComponents();

        // Custom Init
        this.getFrame().setSize(980, 750);
        this.getFrame().setMinimumSize(new Dimension(980, 750));
        System.out.println(this.getFrame().toString());

        importCancelButton.setVisible(false);
        prefs = Preferences.userNodeForPackage(this.getClass());
        db = new CIIFDatabase(this);
        configurePane = new CIIFConfigure(db, this);

        fileChooser = new javax.swing.JFileChooser();
        fileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);

        filterThumbPanel.setSize(this.getFrame().getSize());

        setThumbLayout();

        filterThumbPanel.addComponentListener(new java.awt.event.ComponentAdapter()
		{
			public void componentResized(ComponentEvent e)
			{
                int w = CIIFApp.getApplication().getMainFrame().getWidth();
                int h = CIIFApp.getApplication().getMainFrame().getHeight();
                if (java.lang.Math.abs(w - filterThumbOldWidth) > 200 || java.lang.Math.abs(h - filterThumbOldHeight) > 200) {
                    System.out.println(e.toString());
                    setThumbLayout();
                    System.out.println("gridPanel was resized");
                    filterThumbOldWidth = w;
                    filterThumbOldHeight = h;
                }
			}
		});

        // End custom init
    
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });

        //System.exit(0);
    }
    

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = CIIFApp.getApplication().getMainFrame();
            aboutBox = new CIIFAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        CIIFApp.getApplication().show(aboutBox);
    }

    public CIIFImage getNextImage() {
        if (CIIFImages.size() > 0) {
            CIIFImage ri = CIIFImages.get(0);
            CIIFImages.remove(0);
            return ri;
        } else {
            generateNewImageList();
            if (CIIFImages.size() > 0) {
                CIIFImage ri = CIIFImages.get(0);
                CIIFImages.remove(0);
                return ri;
            } else {
                System.out.println("Out of images!");
                return null;
            }
        }
    }

    private void generateNewImageList() {
        CIIFImages.clear();
        ResultSet rs = db.getRandomImageList(100);
        try {
            while (rs.next()) {
                CIIFImages.add(new CIIFImage(rs.getString(1), db));
            }
       } catch (SQLException sqle) {
            db.printSQLException(sqle);
       }
    }

    private void saveThumbPageStatus() {
        for (thumbPanel t : filterThumbPanelList) {
            t.save();
        }
    }

    private void setThumbLayout() {

        if (filterThumbLock) {
            System.out.println("Thumblock set");
            return;
        }
        
        if (!db.checkDB()) {
            System.out.println("Database is not initialized.  Cannot perform setThumbLayout...");
            return;
        }

        filterThumbLock = true;

        filterThumbGridLayout.setHgap(10);
        filterThumbGridLayout.setVgap(10);
        filterThumbPanel.setLayout(filterThumbGridLayout);
        
        int width = CIIFApp.getApplication().getMainFrame().getWidth() - 50;
        int height = CIIFApp.getApplication().getMainFrame().getHeight() - 50;
        int thumbWidth = 200;
        int thumbHeight = 200;
        int thumbsX = (width / (thumbWidth + 10));
        int thumbsY = (height / (thumbHeight + 10));
        int numThumbs = thumbsX * thumbsY;
        if (numThumbs < 1) numThumbs = 1;

        System.out.println("WIDTH: " + width);

        System.out.println("Width: " + width + "Height: " + height + "numThumbs: " + numThumbs + "thumbsX " + thumbsX);

        if (filterThumbPanelList.size() == 0) {
            System.out.println("size is 0");
            filterThumbPanelList.add(new thumbPanel(getNextImage()));
            filterThumbPanel.add(filterThumbPanelList.get(0).panel, BorderLayout.CENTER);
        }

        System.out.println("size: " + filterThumbPanelList.size() + "  numThumbs: " + numThumbs);
        if (filterThumbPanelList.size() > numThumbs) {
            for (int i = filterThumbPanelList.size() - 1; i >= numThumbs; i--) {
                System.out.println("Removing " + i);
                filterThumbPanel.remove(filterThumbPanelList.get(i).panel);
                filterThumbPanelList.remove(i);
            }
            filterThumbGridLayout.setColumns(thumbsX);
            filterThumbGridLayout.setRows(thumbsY);

        } else if (filterThumbPanelList.size() < numThumbs) {
            for (int i = filterThumbPanelList.size(); i < numThumbs; i++) {
                System.out.println("Adding " + i);
                filterThumbPanelList.add(new thumbPanel(getNextImage()));
                filterThumbPanel.add(filterThumbPanelList.get(i).panel);
            }
            filterThumbGridLayout.setColumns(thumbsX);
            filterThumbGridLayout.setRows(thumbsY);
        }
        System.out.println("size: " + filterThumbPanelList.size() + "  numThumbs: " + numThumbs);
        filterThumbLock = false;

        filterThumbPanel.revalidate();

        System.gc();

     }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        mainTabs = new javax.swing.JTabbedPane();
        importTab = new javax.swing.JPanel();
        sourceLabelText = new javax.swing.JLabel();
        importSourceTabs = new javax.swing.JTabbedPane();
        importLocalTab = new javax.swing.JPanel();
        importLocalPanelBorder = new javax.swing.JPanel();
        importLocalBeginImportPane = new javax.swing.JPanel();
        importLocalImportButton = new javax.swing.JButton();
        importImagePreviewNameLabel = new javax.swing.JLabel();
        importImageFrame = new javax.swing.JPanel();
        importLocalSelectionPane = new javax.swing.JPanel();
        importLocalRecursiveNo = new javax.swing.JRadioButton();
        importLocalAssignImportGroup = new javax.swing.JLabel();
        importLocalBrowseButton = new javax.swing.JButton();
        importLocalRecursiveYes = new javax.swing.JRadioButton();
        importLocalSourceFolderLabel = new javax.swing.JLabel();
        importLocalSourceInput = new javax.swing.JTextField();
        importLocalImportGroupInput = new javax.swing.JTextField();
        importLocalRecursiveLabel = new javax.swing.JLabel();
        importLocalRecursiveYesLabel = new javax.swing.JLabel();
        importLocalrecursiveNoLabel = new javax.swing.JLabel();
        importLocalMessageScrollPane = new javax.swing.JScrollPane();
        importLocalMessageTextArea = new javax.swing.JTextArea();
        importProgressPanel = new javax.swing.JPanel();
        importCancelButton = new javax.swing.JButton();
        importFlickrTab = new javax.swing.JPanel();
        importPicassaTab = new javax.swing.JPanel();
        importWebSpiderTab = new javax.swing.JPanel();
        filterTab = new javax.swing.JPanel();
        filterThumbPanel = new javax.swing.JPanel();
        filterThumbSaveAndDisplayNewSetButton = new javax.swing.JButton();
        filterSourceComboBox = new javax.swing.JComboBox();
        filterSourceLabel = new javax.swing.JLabel();
        exportTab = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        optionsMenu = new javax.swing.JMenu();
        optionsSettingsMenu = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        importRecursiveButtonGroup = new javax.swing.ButtonGroup();

        mainPanel.setMinimumSize(new java.awt.Dimension(1024, 768));
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(1024, 768));

        mainTabs.setName("mainTabs"); // NOI18N

        importTab.setMinimumSize(new java.awt.Dimension(200, 200));
        importTab.setName("importTab"); // NOI18N
        importTab.setPreferredSize(new java.awt.Dimension(1024, 768));

        sourceLabelText.setName("sourceLabelText"); // NOI18N

        importSourceTabs.setName("importSourceTabs"); // NOI18N

        importLocalTab.setName("importLocalTab"); // NOI18N

        importLocalPanelBorder.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        importLocalPanelBorder.setFocusable(false);
        importLocalPanelBorder.setName("importLocalPanelBorder"); // NOI18N

        importLocalBeginImportPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        importLocalBeginImportPane.setName("importLocalBeginImportPane"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ciif.CIIFApp.class).getContext().getResourceMap(CIIFView.class);
        importLocalImportButton.setText(resourceMap.getString("importLocalImportButton.text")); // NOI18N
        importLocalImportButton.setName("importLocalImportButton"); // NOI18N
        importLocalImportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importLocalImportButtonActionPerformed(evt);
            }
        });

        importImagePreviewNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        importImagePreviewNameLabel.setMaximumSize(new java.awt.Dimension(200, 23));
        importImagePreviewNameLabel.setName("importImagePreviewNameLabel"); // NOI18N
        importImagePreviewNameLabel.setPreferredSize(new java.awt.Dimension(200, 23));

        importImageFrame.setMaximumSize(new java.awt.Dimension(200, 200));
        importImageFrame.setMinimumSize(new java.awt.Dimension(100, 100));
        importImageFrame.setName("importImageFrame"); // NOI18N
        importImageFrame.setPreferredSize(new java.awt.Dimension(200, 200));
        importImageFrame.setVerifyInputWhenFocusTarget(false);

        javax.swing.GroupLayout importImageFrameLayout = new javax.swing.GroupLayout(importImageFrame);
        importImageFrame.setLayout(importImageFrameLayout);
        importImageFrameLayout.setHorizontalGroup(
            importImageFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 200, Short.MAX_VALUE)
        );
        importImageFrameLayout.setVerticalGroup(
            importImageFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 200, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout importLocalBeginImportPaneLayout = new javax.swing.GroupLayout(importLocalBeginImportPane);
        importLocalBeginImportPane.setLayout(importLocalBeginImportPaneLayout);
        importLocalBeginImportPaneLayout.setHorizontalGroup(
            importLocalBeginImportPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importLocalBeginImportPaneLayout.createSequentialGroup()
                .addGroup(importLocalBeginImportPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(importLocalBeginImportPaneLayout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(importLocalImportButton))
                    .addGroup(importLocalBeginImportPaneLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(importLocalBeginImportPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(importImagePreviewNameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(importImageFrame, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        importLocalBeginImportPaneLayout.setVerticalGroup(
            importLocalBeginImportPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, importLocalBeginImportPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(importLocalImportButton)
                .addGap(18, 18, 18)
                .addComponent(importImageFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(importImagePreviewNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        importLocalSelectionPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        importLocalSelectionPane.setName("importLocalSelectionPane"); // NOI18N

        importRecursiveButtonGroup.add(importLocalRecursiveNo);
        importLocalRecursiveNo.setName("importLocalRecursiveNo"); // NOI18N

        importLocalAssignImportGroup.setText(resourceMap.getString("importLocalAssignImportGroup.text")); // NOI18N
        importLocalAssignImportGroup.setName("importLocalAssignImportGroup"); // NOI18N

        importLocalBrowseButton.setText(resourceMap.getString("importLocalBrowseButton.text")); // NOI18N
        importLocalBrowseButton.setName("importLocalBrowseButton"); // NOI18N
        importLocalBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importLocalBrowseButtonActionPerformed(evt);
            }
        });

        importRecursiveButtonGroup.add(importLocalRecursiveYes);
        importLocalRecursiveYes.setSelected(true);
        importLocalRecursiveYes.setName("importLocalRecursiveYes"); // NOI18N

        importLocalSourceFolderLabel.setText(resourceMap.getString("importLocalSourceFolderLabel.text")); // NOI18N
        importLocalSourceFolderLabel.setName("importLocalSourceFolderLabel"); // NOI18N

        importLocalSourceInput.setMaximumSize(new java.awt.Dimension(6, 20));
        importLocalSourceInput.setName("importLocalSourceInput"); // NOI18N

        importLocalImportGroupInput.setText(resourceMap.getString("importLocalImportGroupInput.text")); // NOI18N
        importLocalImportGroupInput.setName("importLocalImportGroupInput"); // NOI18N

        importLocalRecursiveLabel.setText(resourceMap.getString("importLocalRecursiveLabel.text")); // NOI18N
        importLocalRecursiveLabel.setName("importLocalRecursiveLabel"); // NOI18N

        importLocalRecursiveYesLabel.setText(resourceMap.getString("importLocalRecursiveYesLabel.text")); // NOI18N
        importLocalRecursiveYesLabel.setName("importLocalRecursiveYesLabel"); // NOI18N

        importLocalrecursiveNoLabel.setText(resourceMap.getString("importLocalrecursiveNoLabel.text")); // NOI18N
        importLocalrecursiveNoLabel.setName("importLocalrecursiveNoLabel"); // NOI18N

        importLocalMessageScrollPane.setBorder(null);
        importLocalMessageScrollPane.setAutoscrolls(true);
        importLocalMessageScrollPane.setName("importLocalMessageScrollPane"); // NOI18N

        importLocalMessageTextArea.setBackground(resourceMap.getColor("importLocalMessageTextArea.background")); // NOI18N
        importLocalMessageTextArea.setColumns(20);
        importLocalMessageTextArea.setEditable(false);
        importLocalMessageTextArea.setFont(resourceMap.getFont("importLocalMessageTextArea.font")); // NOI18N
        importLocalMessageTextArea.setLineWrap(true);
        importLocalMessageTextArea.setRows(5);
        importLocalMessageTextArea.setName("importLocalMessageTextArea"); // NOI18N
        importLocalMessageScrollPane.setViewportView(importLocalMessageTextArea);

        javax.swing.GroupLayout importLocalSelectionPaneLayout = new javax.swing.GroupLayout(importLocalSelectionPane);
        importLocalSelectionPane.setLayout(importLocalSelectionPaneLayout);
        importLocalSelectionPaneLayout.setHorizontalGroup(
            importLocalSelectionPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importLocalSelectionPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(importLocalSelectionPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(importLocalMessageScrollPane)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, importLocalSelectionPaneLayout.createSequentialGroup()
                        .addGroup(importLocalSelectionPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, importLocalSelectionPaneLayout.createSequentialGroup()
                                .addComponent(importLocalRecursiveLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(importLocalRecursiveYesLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(importLocalRecursiveYes)
                                .addGap(34, 34, 34)
                                .addComponent(importLocalrecursiveNoLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(importLocalRecursiveNo)
                                .addGap(155, 155, 155))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, importLocalSelectionPaneLayout.createSequentialGroup()
                                .addComponent(importLocalSourceFolderLabel)
                                .addGap(18, 18, 18)
                                .addComponent(importLocalSourceInput, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, importLocalSelectionPaneLayout.createSequentialGroup()
                                .addComponent(importLocalAssignImportGroup)
                                .addGap(18, 18, 18)
                                .addComponent(importLocalImportGroupInput, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(importLocalBrowseButton)))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        importLocalSelectionPaneLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {importLocalAssignImportGroup, importLocalSourceFolderLabel});

        importLocalSelectionPaneLayout.setVerticalGroup(
            importLocalSelectionPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importLocalSelectionPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(importLocalSelectionPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(importLocalSourceFolderLabel)
                    .addComponent(importLocalSourceInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(importLocalBrowseButton))
                .addGap(4, 4, 4)
                .addGroup(importLocalSelectionPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(importLocalAssignImportGroup)
                    .addComponent(importLocalImportGroupInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(importLocalSelectionPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(importLocalRecursiveLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(importLocalRecursiveYesLabel)
                    .addComponent(importLocalRecursiveYes)
                    .addComponent(importLocalRecursiveNo)
                    .addComponent(importLocalrecursiveNoLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(importLocalMessageScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                .addContainerGap())
        );

        importLocalSelectionPaneLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {importLocalRecursiveNo, importLocalRecursiveYes, importLocalRecursiveYesLabel, importLocalrecursiveNoLabel});

        javax.swing.GroupLayout importLocalPanelBorderLayout = new javax.swing.GroupLayout(importLocalPanelBorder);
        importLocalPanelBorder.setLayout(importLocalPanelBorderLayout);
        importLocalPanelBorderLayout.setHorizontalGroup(
            importLocalPanelBorderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, importLocalPanelBorderLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(importLocalSelectionPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(importLocalBeginImportPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        importLocalPanelBorderLayout.setVerticalGroup(
            importLocalPanelBorderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importLocalPanelBorderLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(importLocalPanelBorderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(importLocalBeginImportPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(importLocalSelectionPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        importProgressPanel.setMaximumSize(new java.awt.Dimension(823, 17));
        importProgressPanel.setName("importProgressPanel"); // NOI18N

        javax.swing.GroupLayout importProgressPanelLayout = new javax.swing.GroupLayout(importProgressPanel);
        importProgressPanel.setLayout(importProgressPanelLayout);
        importProgressPanelLayout.setHorizontalGroup(
            importProgressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 823, Short.MAX_VALUE)
        );
        importProgressPanelLayout.setVerticalGroup(
            importProgressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 17, Short.MAX_VALUE)
        );

        importCancelButton.setText(resourceMap.getString("importCancelButton.text")); // NOI18N
        importCancelButton.setEnabled(false);
        importCancelButton.setName("importCancelButton"); // NOI18N
        importCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importCancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout importLocalTabLayout = new javax.swing.GroupLayout(importLocalTab);
        importLocalTab.setLayout(importLocalTabLayout);
        importLocalTabLayout.setHorizontalGroup(
            importLocalTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importLocalTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(importLocalTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, importLocalTabLayout.createSequentialGroup()
                        .addComponent(importProgressPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(importCancelButton))
                    .addComponent(importLocalPanelBorder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        importLocalTabLayout.setVerticalGroup(
            importLocalTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importLocalTabLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(importLocalPanelBorder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(importLocalTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(importProgressPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(importCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 17, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        importSourceTabs.addTab("Local Disk", importLocalTab);

        importFlickrTab.setName("importFlickrTab"); // NOI18N

        javax.swing.GroupLayout importFlickrTabLayout = new javax.swing.GroupLayout(importFlickrTab);
        importFlickrTab.setLayout(importFlickrTabLayout);
        importFlickrTabLayout.setHorizontalGroup(
            importFlickrTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 922, Short.MAX_VALUE)
        );
        importFlickrTabLayout.setVerticalGroup(
            importFlickrTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 382, Short.MAX_VALUE)
        );

        importSourceTabs.addTab("Flickr", importFlickrTab);

        importPicassaTab.setName("importPicassaTab"); // NOI18N

        javax.swing.GroupLayout importPicassaTabLayout = new javax.swing.GroupLayout(importPicassaTab);
        importPicassaTab.setLayout(importPicassaTabLayout);
        importPicassaTabLayout.setHorizontalGroup(
            importPicassaTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 922, Short.MAX_VALUE)
        );
        importPicassaTabLayout.setVerticalGroup(
            importPicassaTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 382, Short.MAX_VALUE)
        );

        importSourceTabs.addTab("Picassa", importPicassaTab);

        importWebSpiderTab.setName("importWebSpiderTab"); // NOI18N

        javax.swing.GroupLayout importWebSpiderTabLayout = new javax.swing.GroupLayout(importWebSpiderTab);
        importWebSpiderTab.setLayout(importWebSpiderTabLayout);
        importWebSpiderTabLayout.setHorizontalGroup(
            importWebSpiderTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 922, Short.MAX_VALUE)
        );
        importWebSpiderTabLayout.setVerticalGroup(
            importWebSpiderTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 382, Short.MAX_VALUE)
        );

        importSourceTabs.addTab("Web spider", importWebSpiderTab);

        javax.swing.GroupLayout importTabLayout = new javax.swing.GroupLayout(importTab);
        importTab.setLayout(importTabLayout);
        importTabLayout.setHorizontalGroup(
            importTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(importTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(importSourceTabs, javax.swing.GroupLayout.PREFERRED_SIZE, 927, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sourceLabelText))
                .addContainerGap(80, Short.MAX_VALUE))
        );
        importTabLayout.setVerticalGroup(
            importTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(sourceLabelText)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(importSourceTabs, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(342, 342, 342))
        );

        mainTabs.addTab("Import Images", importTab);

        filterTab.setName("filterTab"); // NOI18N

        filterThumbPanel.setName("filterThumbPanel"); // NOI18N

        javax.swing.GroupLayout filterThumbPanelLayout = new javax.swing.GroupLayout(filterThumbPanel);
        filterThumbPanel.setLayout(filterThumbPanelLayout);
        filterThumbPanelLayout.setHorizontalGroup(
            filterThumbPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 995, Short.MAX_VALUE)
        );
        filterThumbPanelLayout.setVerticalGroup(
            filterThumbPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 689, Short.MAX_VALUE)
        );

        filterThumbSaveAndDisplayNewSetButton.setText(resourceMap.getString("filterThumbSaveAndDisplayNewSetButton.text")); // NOI18N
        filterThumbSaveAndDisplayNewSetButton.setName("filterThumbSaveAndDisplayNewSetButton"); // NOI18N
        filterThumbSaveAndDisplayNewSetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filterThumbSaveAndDisplayNewSetButtonActionPerformed(evt);
            }
        });

        filterSourceComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Inbox", "All" }));
        filterSourceComboBox.setName("filterSourceComboBox"); // NOI18N

        filterSourceLabel.setText(resourceMap.getString("filterSourceLabel.text")); // NOI18N
        filterSourceLabel.setName("filterSourceLabel"); // NOI18N

        javax.swing.GroupLayout filterTabLayout = new javax.swing.GroupLayout(filterTab);
        filterTab.setLayout(filterTabLayout);
        filterTabLayout.setHorizontalGroup(
            filterTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filterTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(filterTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(filterThumbPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(filterTabLayout.createSequentialGroup()
                        .addComponent(filterThumbSaveAndDisplayNewSetButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(filterSourceLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filterSourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        filterTabLayout.setVerticalGroup(
            filterTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filterTabLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(filterTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(filterThumbSaveAndDisplayNewSetButton)
                    .addComponent(filterSourceLabel)
                    .addComponent(filterSourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(filterThumbPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainTabs.addTab("Filter Images", filterTab);

        exportTab.setName("exportTab"); // NOI18N

        javax.swing.GroupLayout exportTabLayout = new javax.swing.GroupLayout(exportTab);
        exportTab.setLayout(exportTabLayout);
        exportTabLayout.setHorizontalGroup(
            exportTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1019, Short.MAX_VALUE)
        );
        exportTabLayout.setVerticalGroup(
            exportTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 750, Short.MAX_VALUE)
        );

        mainTabs.addTab("Export Images", exportTab);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 1024, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 777, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(ciif.CIIFApp.class).getContext().getActionMap(CIIFView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        optionsMenu.setText(resourceMap.getString("optionsMenu.text")); // NOI18N
        optionsMenu.setName("optionsMenu"); // NOI18N

        optionsSettingsMenu.setText(resourceMap.getString("optionsSettingsMenu.text")); // NOI18N
        optionsSettingsMenu.setName("optionsSettingsMenu"); // NOI18N
        optionsSettingsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                optionsSettingsMenuActionPerformed(evt);
            }
        });
        optionsMenu.add(optionsSettingsMenu);

        menuBar.add(optionsMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1024, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 840, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    public void updateImportImageDisplay(BufferedImage img, String path, Boolean enabled) {
        importImageDisplay.setIcon(new ImageIcon(img));
        if (enabled) {
           importImagePreviewNameLabel.setText(path);
        } else {
           importImagePreviewNameLabel.setText("Dupe: " + path);
        }
        importImageFrame.revalidate();
    }

    public void updateImportLocalMessages(String msg) {
        importLocalMessageTextArea.append(msg + "\n");
        importLocalMessageTextArea.setCaretPosition(importLocalMessageTextArea.getDocument().getLength());
    }

    public void finishLocalImport(javax.swing.JProgressBar bar) {
        updateImportLocalMessages("Local import finished.");
        enableAll();

        importLocalSourceInput.setText("");
        importProgressPanel.remove(bar);
        importProgressPanel.revalidate();
        importCancelButton.setEnabled(false);
        importCancelButton.setVisible(false);
    }

    private void enableTree(Container root, boolean enable) {
        for (Component component : root.getComponents()) {
            if (component instanceof Container) {
                enableTree((Container)component, enable);
                component.setEnabled(enable);
            } else {
                component.setEnabled(enable);
            }
        }
    }

    public void disableAll() {
        enableTree(mainPanel, false);
        optionsMenu.setEnabled(false);
        enableTree(importImageFrame, true);
        importImagePreviewNameLabel.setEnabled(true);
    }

    public void enableAll() {
        enableTree(mainPanel, true);
        optionsMenu.setEnabled(true);
    }

    public CIIFDatabase reloadDB() {
        db = null;
        db = new CIIFDatabase(this);
        return db;
    }

    public CIIFDatabase getDB() {
        return db;
    }

    private void importLocalImportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importLocalImportButtonActionPerformed
        File tempFolder = new File(prefs.get("TEMPFOLDER", ""));
        if (! tempFolder.isDirectory() || ! tempFolder.canWrite()) {
            String msg = "Temp Directory is invalid or unset.  Please set a valid one from the Options -> Settings menu.";
            importLocalMessageTextArea.append("ERROR: " + msg + "\n");
            javax.swing.JOptionPane.showMessageDialog(CIIFApp.getApplication().getMainFrame(), msg, "Error: Invalid Temp Directory", javax.swing.JOptionPane.ERROR_MESSAGE);
            enableAll();
            openConfigurePane();
            return;
        } else {
            File tempCIIF = new File(prefs.get("TEMPFOLDER", "") + File.separator + "CI-IF");
            tempCIIF.mkdir();
        }
        
        File spiderRoot = new File(importLocalSourceInput.getText());
        if (! spiderRoot.isDirectory() || ! spiderRoot.canRead()) {
            String msg = "Source Folder is invalid or unset.  Please provide a valid one.";
            importLocalMessageTextArea.append("ERROR: " + msg + "\n");
            javax.swing.JOptionPane.showMessageDialog(CIIFApp.getApplication().getMainFrame(), msg, "Error: Invalid Source Folder", javax.swing.JOptionPane.ERROR_MESSAGE);
            enableAll();
            return;
        }

        if (!db.checkDB()) {
            if (!db.loadDB(importLocalImportButton, true)) {
                String msg = "Database Directory is invalid or unset.  Please configure a valid one from the Options -> Settings menu.";
                javax.swing.JOptionPane.showMessageDialog(CIIFApp.getApplication().getMainFrame(), msg, "Error: Invalid Database Directory", javax.swing.JOptionPane.ERROR_MESSAGE);
                openConfigurePane();
                return;
            }
            return;
        }

        javax.swing.JProgressBar importLocalProgressBar = new javax.swing.JProgressBar(0, 100);
        importLocalProgressBar.setValue(0);
        importLocalProgressBar.setStringPainted(true);
        importLocalProgressBar.setIndeterminate(true);
        importLocalProgressBar.setString("Indexing...");
        importLocalProgressBar.setVisible(false);

        importLocalProgressBar.setVisible(true);

        configurePane.setVisible(false);
        disableAll();

        importImageFrame.setEnabled(true);

        importImageFrame.setLayout(new BorderLayout());
        importImageFrame.add(importImageDisplay, BorderLayout.SOUTH);
        importImagePreviewNameLabel.setText(importLocalSourceInput.getText());

        importProgressPanel.setLayout(new BorderLayout());
        importProgressPanel.add(importLocalProgressBar, BorderLayout.SOUTH);
        importProgressPanel.revalidate();
        
        importCancelButton.setEnabled(true);
        importCancelButton.setVisible(true);

        CIIFImportLocalTaskListener listener = new CIIFImportLocalTaskListener();
        importTask = new CIIFImportLocalTask(this, listener, spiderRoot.getAbsolutePath(), importLocalProgressBar, importLocalRecursiveYes.isSelected(), importLocalImportGroupInput.getText(), db);
        listener.setPBar(importLocalProgressBar);
        importTask.addPropertyChangeListener(listener);
        importTask.execute();

        
    }//GEN-LAST:event_importLocalImportButtonActionPerformed

    private void importLocalBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importLocalBrowseButtonActionPerformed
             int returnVal = this.fileChooser.showOpenDialog(importLocalTab);
             if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
                  File file = fileChooser.getSelectedFile();
                  this.importLocalSourceInput.setText(file.getPath());
             }
    }//GEN-LAST:event_importLocalBrowseButtonActionPerformed

    public void openConfigurePane() {
        configurePane.configureSetLocationFix();
        configurePane.setVisible(true);
    }

    private void optionsSettingsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionsSettingsMenuActionPerformed
        openConfigurePane();
    }//GEN-LAST:event_optionsSettingsMenuActionPerformed

    private void importCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importCancelButtonActionPerformed
        importTask.cancel(true);
    }//GEN-LAST:event_importCancelButtonActionPerformed

    private void filterThumbSaveAndDisplayNewSetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterThumbSaveAndDisplayNewSetButtonActionPerformed
        enableAll();
        if (!db.checkDB()) {
            if (!db.loadDB(filterThumbSaveAndDisplayNewSetButton, false)) {
                String msg = "Database Directory is invalid or unset.  Please configure a valid one from the Options -> Settings menu.";
                javax.swing.JOptionPane.showMessageDialog(CIIFApp.getApplication().getMainFrame(), msg, "Error: Invalid Database Directory", javax.swing.JOptionPane.ERROR_MESSAGE);
                openConfigurePane();
            }
            return;
        }
        saveThumbPageStatus();
        for (thumbPanel t : filterThumbPanelList) {
            filterThumbPanel.remove(t.panel);
        }
        filterThumbPanelList.clear();
        setThumbLayout();
}//GEN-LAST:event_filterThumbSaveAndDisplayNewSetButtonActionPerformed

    private javax.swing.JLabel importImageDisplay = new JLabel();
    private javax.swing.JFileChooser fileChooser;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel exportTab;
    private javax.swing.JComboBox filterSourceComboBox;
    private javax.swing.JLabel filterSourceLabel;
    private javax.swing.JPanel filterTab;
    private javax.swing.JPanel filterThumbPanel;
    private javax.swing.JButton filterThumbSaveAndDisplayNewSetButton;
    private javax.swing.JButton importCancelButton;
    private javax.swing.JPanel importFlickrTab;
    private javax.swing.JPanel importImageFrame;
    private javax.swing.JLabel importImagePreviewNameLabel;
    private javax.swing.JLabel importLocalAssignImportGroup;
    private javax.swing.JPanel importLocalBeginImportPane;
    private javax.swing.JButton importLocalBrowseButton;
    private javax.swing.JButton importLocalImportButton;
    private javax.swing.JTextField importLocalImportGroupInput;
    private javax.swing.JScrollPane importLocalMessageScrollPane;
    private javax.swing.JTextArea importLocalMessageTextArea;
    private javax.swing.JPanel importLocalPanelBorder;
    private javax.swing.JLabel importLocalRecursiveLabel;
    private javax.swing.JRadioButton importLocalRecursiveNo;
    private javax.swing.JRadioButton importLocalRecursiveYes;
    private javax.swing.JLabel importLocalRecursiveYesLabel;
    private javax.swing.JPanel importLocalSelectionPane;
    private javax.swing.JLabel importLocalSourceFolderLabel;
    private javax.swing.JTextField importLocalSourceInput;
    private javax.swing.JPanel importLocalTab;
    private javax.swing.JLabel importLocalrecursiveNoLabel;
    private javax.swing.JPanel importPicassaTab;
    private javax.swing.JPanel importProgressPanel;
    private javax.swing.ButtonGroup importRecursiveButtonGroup;
    private javax.swing.JTabbedPane importSourceTabs;
    private javax.swing.JPanel importTab;
    private javax.swing.JPanel importWebSpiderTab;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTabbedPane mainTabs;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu optionsMenu;
    private javax.swing.JMenuItem optionsSettingsMenu;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel sourceLabelText;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
